{include file="public/header"}
<body>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-tool" >
            <div class="ht-tool-left" v-if="1==2">
                <el-button type="success" size="mini" icon="el-icon-plus" @click="doAdd">添加</el-button>
            </div>
            <div class="ht-tool-right">
            </div>
        </div>
        <div class="ht-main-body" style="padding-top: 10px">
            <el-table :data="tableData" border header-row-class-name="ht-table-header">
                <el-table-column
                        align="center"
                        prop="id"
                        label="ID"
                        width="100">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="title"
                        label="标题">
                    <template slot-scope="scope">
                        <ht-tag :color="scope.row.color" :value="scope.row.title"></ht-tag>
                    </template>
                </el-table-column>
                <el-table-column align="center"
                                 prop="create_time"
                                 label="添加时间">
                </el-table-column>

                <el-table-column
                        align="center"
                        label="操作">
                    <template slot-scope="scope">
                        <el-button @click="set(scope.row)" size="mini" type="primary" icon="el-icon-setting" v-if="scope.row.id !== 1"></el-button>
                        <el-button @click="edit(scope.row)" size="mini" type="primary" icon="el-icon-edit"></el-button>
                        <el-button @click="del(scope.row)" v-if="scope.row.id !== 1" size="mini" type="danger" icon="el-icon-delete"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="ht-main-page">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page"
                        :page-sizes="[1,10, 200, 300, 400]"
                        :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
            <el-drawer
                    :visible.sync="is_edit"
                    size="90%"
                    :with-header="false"
                    custom-class="ht-drawer-bg"
            >
                <div class="ht-drawer-main">
                    <el-page-header @back="goBack" title="Esc返回" :content="content"></el-page-header>
                    <div class="ht-form">
                        <el-form :model="editData" label-width="90px" size="small">
                            <el-form-item label="标题" >
                                <el-input placeholder="标题" v-model="editData.title"
                                          style="width: 50%"></el-input>
                            </el-form-item>
                            <el-form-item label="背景" >
                                <el-row :gutter="10">
                                    <el-col :span="5">
                                        <el-input placeholder="背景" v-model="editData.color"></el-input>
                                    </el-col>
                                    <el-col :span="1">
                                        <el-color-picker v-model="editData.color"></el-color-picker>
                                    </el-col>
                                </el-row>
                            </el-form-item>

                            <el-form-item >
                                <el-button @click="goBack">取消</el-button>
                                <el-button type="primary" @click="onSubmit">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-drawer>
            <el-drawer
                    :visible.sync="is_set"
                    size="97%"
                    :with-header="true"
                    direction="btt"
                    custom-class="ht-drawer-bg"
            >
                <div class="ht-drawer-main">
                    <el-page-header @back="goBack" title="Esc返回" :content="content"></el-page-header>
                    <div class="ht-form">
                        <el-form :model="editData" label-width="90px" size="small">
                            <el-form-item label="标题" >
                                <el-input placeholder="标题" v-model="editData.title"
                                          style="width: 50%"></el-input>
                            </el-form-item>
                            <el-form-item label="背景" >
                                <el-row :gutter="10">
                                    <el-col :span="5">
                                        <el-input placeholder="背景" v-model="editData.color"></el-input>
                                    </el-col>
                                    <el-col :span="1">
                                        <el-color-picker v-model="editData.color"></el-color-picker>
                                    </el-col>
                                </el-row>
                            </el-form-item>

                            <el-form-item >
                                <el-button @click="goBack">取消</el-button>
                                <el-button type="primary" @click="onSubmit">提交</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </el-drawer>
        </div>

    </div>
</div>


{include file="public/common"}
<script>
    new Vue({
        el: "#app",
        data: function () {
            return {
                arctypeList: [],
                activeTab: 'first',
                tableData: [],
                is_edit: false,
                is_set:false,
                editData: {
                    "color": "#409EFF",
                    "title": '',
                },
                editDataTemp: {
                    "color": "#409EFF",
                    "title": '',
                },
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                search_arctype_id: "",
                search_title: "",
                editBody: '13123',
                pre_view: []
            }
        },
        created: function () {
            this.getData()
        },
        methods: {
            set(data) {
                location.href = "{:url('groupRuleList')}?id=" + data.id;
                this.is_set = true
            },
            uploadSuccess(response, file, fileList) {
                if (response.code === 1) {
                    this.editDataTemp.litpic = response.url
                    this.editData.litpic = response.url
                    this.pre_view = [response.url]
                    console.log('response.url', this.editData.litpic)
                }
                console.log(response, file, fileList)
            },
            changeStatus: function (e, id) {
                axios.post("{:url('Banner/bannerStatus')}", {id: id}).then((res) => {
                    if (res.data.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            doSearch: function () {
                this.getData()
            },
            onSubmit() {
                var that = this
                $.post('{:url("Auth/authGroupAdd")}', that.editData, function (res) {
                    if (res.code == 1) {
                        that.showSuccessMsgCall(function () {
                            location.reload();
                        })
                    } else {
                        that.showErrorMsg( res.msg)
                    }
                })

            },
            getData: function () {
                var that = this
                axios.post('{:url("Auth/authGroupList")}', {
                    limit: that.limit,
                    page: that.page,
                }).then((res) => {
                    console.log(res.data)
                    that.tableData = res.data.data.data
                    that.total = res.data.data.total
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = this.editDataTemp
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data
                console.log(data)
            },
            goBack: function () {
                this.is_edit = false
                this.is_set = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    axios.post('{:url("Auth/authGroupDel")}', {id: data.id}).then((res) => {
                        let result = res.data;
                        if (result.code === 1) {
                            that.showSuccessMsgCall(function () {
                                location.reload()
                            })
                        } else {
                            that.showErrorMsg(result.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
